package com.pshdhx.aiagent.rag;

import jakarta.annotation.Resource;
import org.springframework.ai.document.Document;
import org.springframework.ai.embedding.EmbeddingModel;
import org.springframework.ai.vectorstore.SimpleVectorStore;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

/**
 * @Author pansd
 * @Date 2025-07-03 18:53
 * @Des
 */
@Configuration
public class LoveAppVectorStoreConfig {

    @Resource
    private DocumentLoaderMarkDown documentLoaderMarkDown;

    @Resource
    private MetaDataExtractConfig metaDataExtractConfig;

    @Bean
    VectorStore loveAppVectorStore(EmbeddingModel dashscopeEmbeddingModel) {
        SimpleVectorStore simpleVectorStore = SimpleVectorStore.builder(dashscopeEmbeddingModel)
                .build();
        // 加载文档
        List<Document> documents = documentLoaderMarkDown.loadMarkdowns();
        List<Document> documentsKeyWords = metaDataExtractConfig.extractMetaData(documents);
        simpleVectorStore.add(documentsKeyWords);
        return simpleVectorStore;
    }
}
